package com.example.arithmeticleetcode.leetcode.July;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-07-24 10:08
 **/
public class Demo09 {

    public static void main(String[] args) {
        int[] A1 = {0, 1, 0};
        int[] A2 = {0, 2, 1, 0};
        System.out.println(peakIndexInMountainArray(A1));
        System.out.println(peakIndexInMountainArray(A2));
    }

    public static int peakIndexInMountainArray(int[] A) {
        for (int i = 1, len = A.length - 1; i < len; i++) {
            if (A[i - 1] < A[i] && A[i] > A[i + 1]) {
                return i;
            }
        }
        return -1;
    }
}
